<?php
namespace App\Http\Controllers\Admin;
use Maatwebsite\Excel\Facades\Excel;
use App\Exports\ExcelExport;
use App\Http\Controllers\Controller;
use App\Utils\ResponseUtil;
use App\DTOS\Admin\FeedBackSearchDTO;
use App\Services\FeedBackService;
use App\DTOS\Admin\FeedBackInsertDTO;
use App\DTOS\Admin\FeedBackUpdateDTO;
// 游戏反馈管理
class FeedBackController extends Controller
{
    private FeedBackService $service;

    /**
    * FeedBackService constructor.
    * @param  FeedBackService $service
    */
    public function __construct(FeedBackService $service)
    {
        $this->service = $service;
    }

    public function paginate()
    {
        $DTO = new FeedBackSearchDTO(request()->all());
        $paginate = $this->service->paginate($DTO);
        $data = $paginate->items();

        $res = [];
        $res['code'] = 0;
        $res['data'] = $data;
        $res['count'] = $paginate->total();
        return ResponseUtil::json($res);
    }

    public function update($id)
    {
        try{

            $DTO = new FeedBackUpdateDTO(request()->post());
            $this->service->updateById($id,$DTO);
            return ResponseUtil::success();
        } catch (\Exception $e){
            return ResponseUtil::error($e->getMessage());
        }
    }

    public function delete($id){
        try{
            $this->service->deleteById($id);
            return ResponseUtil::success();
        } catch (\Exception $e){
            return ResponseUtil::error($e->getMessage());
        }
    }
    public function detail($id)
    {
        $data = $this->service->getById($id);
        return ResponseUtil::success($data);
    }

}
